package com.delayTask.wheelTimer;

import com.delayTask.DelayTaskQueue;
import com.delayTask.delayQueue.DelayQueueAutoConfiguration;
import io.netty.util.HashedWheelTimer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 大忽悠
 * @create 2022/9/20 14:23
 */
@ConditionalOnClass(HashedWheelTimer.class)
@AutoConfigureBefore(DelayQueueAutoConfiguration.class)
@Configuration
@ConditionalOnMissingBean(DelayTaskQueue.class)
@ConditionalOnProperty(prefix = "delayQueue.wheelTimer", name = "duration")
@EnableConfigurationProperties(WheelTimerProperties.class)
@Slf4j
public class WheelTimerDelayQueueAutoConfiguration {

    @Bean
    public DelayTaskQueue delayTaskQueue(WheelTimerProperties wheelTimerProperties){
        log.info("使用时间轮wheelTimer作为延迟队列使用");
        return new WheelTimerDelayQueue(wheelTimerProperties.getDuration());
   }
}
